﻿namespace WMS6.Web
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web.MessageServiceRef;

    public class WebForm_Logo : BasePage
    {
        protected Button btnServerTime;
        protected HtmlForm form1;
        protected HtmlInputHidden hdnCurrentWH;
        protected HtmlInputHidden hdnFullLanguageOption;
        protected HtmlInputHidden hdnLoginPageFrom;
        protected HtmlInputHidden hdnMessageDisplayNum;
        protected HtmlInputHidden hdnPerfLanguage;
        protected HtmlInputHidden hdnUserID;
        protected HtmlInputHidden hdnUserMessageDisplayTime;
        protected HtmlInputHidden hdnUserMessageTime;
        protected HtmlInputHidden henPerfStyle;
        protected Label lblServerTime;
        protected Label lblUnreadMessageQty;
        protected Label lblWelcome;
        protected HtmlImage messageImg;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;
        protected HtmlGenericControl title_logo;
        protected UpdatePanel up1;

        protected void btnServerTime_Click(object sender, EventArgs e)
        {
            this.lblServerTime.Text = DateTime.Now.ToString();
            this.GetMessageInfo();
        }

        private void GetMessageInfo()
        {
            try
            {
                if (base.UserInfo != null)
                {
                    UserUnreadMessageInfo userUnreadMessage = MessageServiceClientProxy.GetInstance().GetUserUnreadMessageByID(base.UserInfo.UserID);
                    if (userUnreadMessage != null)
                    {
                        this.messageImg.Src = "Images/msgB.gif";
                        this.messageImg.Visible = true;
                        this.lblUnreadMessageQty.Text = userUnreadMessage.UnreadQty.ToString();
                        DateTime dtNow = DateTime.Now;
                        if (userUnreadMessage.UpdatedDate.AddSeconds((double) int.Parse(this.hdnMessageDisplayNum.Value)) > dtNow)
                        {
                            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", string.Concat(new object[] { "<script language='javascript'>ShowMessageDiv(", userUnreadMessage.RowID, ",'", userUnreadMessage.MessageTitle, "','", userUnreadMessage.MessageContent, "');</script>" }), false);
                        }
                    }
                    else
                    {
                        this.messageImg.Src = "Images/msgA.gif";
                        this.messageImg.Visible = false;
                        this.lblUnreadMessageQty.Text = "";
                    }
                }
            }
            catch
            {
            }
        }

        private void GetUserMessageSetting()
        {
            this.hdnUserMessageDisplayTime.Value = base.GetValueFromAppSettings("USER_MESSAGE");
        }

        private void LoadData()
        {
            this.henPerfStyle.Value = base.ChangeStylePattern(base.UserInfo.Preference.Themes);
            this.hdnPerfLanguage.Value = base.ChangeLangeugePattern(base.UserInfo.Preference.Lang);
            this.hdnFullLanguageOption.Value = base.UserInfo.Preference.Lang;
            if (base.UserInfo.Preference.Lang.ToUpper() == "ZH-CN")
            {
                this.lblWelcome.Text = "欢迎 : " + base.UserInfo.UserName + "  &nbsp; &nbsp; &nbsp;当前登录仓库 : " + base.UserInfo.WhDbDesc;
            }
            else if (base.UserInfo.Preference.Lang.ToUpper() == "ZH-TW")
            {
                this.lblWelcome.Text = "歡迎 : " + base.UserInfo.UserName + "  &nbsp; &nbsp; &nbsp;當前登錄倉庫 : " + base.UserInfo.WhDbDesc;
            }
            else
            {
                this.lblWelcome.Text = "Welcome : " + base.UserInfo.UserName + "  &nbsp; &nbsp; &nbsp;Current Warehouse : " + base.UserInfo.WhDbDesc;
            }
            string strTitleLogo = base.GetValueFromAppSettings("PAGE_TITLE_LOGO");
            if (!string.IsNullOrEmpty(strTitleLogo))
            {
                this.title_logo.Attributes.Add("style", "cursor:hand;background-image: url(Images/" + strTitleLogo + ");height: 100%;width: 100%;");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Response.Buffer = false;
            this.Page.Response.Cache.SetNoStore();
            if (this.Session["UserInfo"] == null)
            {
                if (this.hdnLoginPageFrom.Value == "login")
                {
                    base.Response.Write("<script language=javascript>top.location.href='Login.aspx'</script>");
                    base.Response.Write("<script language=javascript>windows.parent.close()</script>");
                }
                else
                {
                    base.Response.Write("<script language=javascript>top.location.href='Portal.aspx'</script>");
                    base.Response.Write("<script language=javascript>windows.parent.close()</script>");
                }
            }
            if (!base.IsPostBack)
            {
                this.LoadData();
                this.GetUserMessageSetting();
                this.GetMessageInfo();
                if (this.Session["LoginPageFrom"] != null)
                {
                    this.hdnLoginPageFrom.Value = this.Session["LoginPageFrom"].ToString();
                }
                else
                {
                    this.hdnLoginPageFrom.Value = "login";
                }
                this.Session["LoginPageFrom"] = null;
            }
        }
    }
}

